home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / caldr / caldr1.frm next >
Text File  |  1995-05-08  |  14KB  |  529 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Calendar Demo"
  5.    ClientHeight    =   4020
  6.    ClientLeft      =   1080
  7.    ClientTop       =   1485
  8.    ClientWidth     =   7365
  9.    Height          =   4425
  10.    Left            =   1020
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   268
  13.    ScaleMode       =   3  'Pixel
  14.    ScaleWidth      =   491
  15.    Top             =   1140
  16.    Width           =   7485
  17.    Begin CommandButton Command1 
  18.       Caption         =   "Calendar"
  19.       Height          =   525
  20.       Left            =   1140
  21.       TabIndex        =   7
  22.       Top             =   165
  23.       Width           =   1665
  24.    End
  25.    Begin PictureBox Calendar 
  26.       AutoRedraw      =   -1  'True
  27.       BackColor       =   &H00C0C0C0&
  28.       ForeColor       =   &H00800000&
  29.       Height          =   1800
  30.       Left            =   4590
  31.       ScaleHeight     =   118
  32.       ScaleMode       =   3  'Pixel
  33.       ScaleWidth      =   147
  34.       TabIndex        =   0
  35.       Top             =   255
  36.       Visible         =   0   'False
  37.       Width           =   2235
  38.       Begin SSCommand btnMonth 
  39.          BevelWidth      =   0
  40.          Caption         =   "Command3D1"
  41.          Font3D          =   0  'None
  42.          Height          =   285
  43.          Index           =   0
  44.          Left            =   615
  45.          TabIndex        =   5
  46.          Top             =   570
  47.          Width           =   315
  48.       End
  49.       Begin SSCommand btnYear 
  50.          BevelWidth      =   0
  51.          Caption         =   "Command3D1"
  52.          Font3D          =   0  'None
  53.          Height          =   300
  54.          Index           =   0
  55.          Left            =   1005
  56.          TabIndex        =   2
  57.          Top             =   405
  58.          Width           =   315
  59.       End
  60.       Begin PictureBox Picture1 
  61.          AutoRedraw      =   -1  'True
  62.          BackColor       =   &H00C0C0C0&
  63.          Height          =   375
  64.          Left            =   120
  65.          ScaleHeight     =   23
  66.          ScaleMode       =   3  'Pixel
  67.          ScaleWidth      =   24
  68.          TabIndex        =   1
  69.          Top             =   645
  70.          Width           =   390
  71.          Begin PictureBox Picture2 
  72.             BackColor       =   &H00000000&
  73.             BorderStyle     =   0  'None
  74.             ForeColor       =   &H00C0C0C0&
  75.             Height          =   165
  76.             Left            =   90
  77.             ScaleHeight     =   11
  78.             ScaleMode       =   3  'Pixel
  79.             ScaleWidth      =   14
  80.             TabIndex        =   6
  81.             Top             =   75
  82.             Width           =   210
  83.          End
  84.       End
  85.       Begin Label lblMonth 
  86.          BorderStyle     =   1  'Fixed Single
  87.          Caption         =   "Label1"
  88.          Height          =   165
  89.          Left            =   180
  90.          TabIndex        =   4
  91.          Top             =   330
  92.          Width           =   630
  93.       End
  94.       Begin Label lblYear 
  95.          BorderStyle     =   1  'Fixed Single
  96.          Caption         =   "Label1"
  97.          Height          =   210
  98.          Left            =   225
  99.          TabIndex        =   3
  100.          Top             =   120
  101.          Width           =   870
  102.       End
  103.    End
  104.    Begin Label Label1 
  105.       BackColor       =   &H00C0C0C0&
  106.       Caption         =   "Click button to display calendar.  Clicking on a date highlights and sets it. A set date can be removed by double clicking on it.  Feel free to improve upon.  Any suggestions to speed display when you advance or retard the calendar with the arrows would be appreciated. This just shows what's possible with VB, alone.  Much was suggested by  VB Knowledge Base article,  ""How to Make a Spreadsheet-style Grid that Allows Editing"". I do contract programming in VB and Access and would appreciate any leads for work you can pass my way.                                        Glenn Silverman :  CompuServe 71450,2750"
  107.       Height          =   2820
  108.       Left            =   225
  109.       TabIndex        =   8
  110.       Top             =   825
  111.       Width           =   3945
  112.    End
  113. End
  114. 'Max grid size
  115. Const grid_col_max = 10
  116. Const grid_row_max = 20
  117.  
  118. 'grid dimensions
  119. Dim w As Single
  120. Dim h As Single
  121.  
  122. 'Current grid size
  123. Dim grid_cols As Integer
  124. Dim grid_rows As Integer
  125.  
  126. 'Current cell position
  127. Dim grid_col As Integer
  128. Dim grid_row As Integer
  129.  
  130. 'Grid string contents
  131. Dim grid_text(35) As String
  132.  
  133. 'Grid cell numbers
  134. Dim cell(35) As Rect
  135.  
  136. 'Grid line positions
  137. Dim grid_line_col(grid_col_max) As Integer
  138. Dim grid_line_row(grid_row_max) As Integer
  139.  
  140. 'Calendar date setting
  141. Dim calDate As Long
  142.  
  143. Sub AdvanceMonth ()
  144.     Dim c, m, y, ds
  145.     c = DateValue(lblMonth + " 1, " + lblYear)
  146.     m = Month(c) + 1
  147.     If m = 13 Then
  148.         m = 1
  149.         y = Year(c) + 1
  150.     Else
  151.         y = Year(c)
  152.     End If
  153.     ds = DateSerial(y, m, 1)
  154.     ShowMonth ds
  155. End Sub
  156.  
  157. Sub AdvanceYear ()
  158.     Dim c, m, y, ds
  159.     c = DateValue(lblMonth + " 1, " + lblYear)
  160.     y = Year(c) + 1
  161.     m = Month(c)
  162.     ds = DateSerial(y, m, 1)
  163.     ShowMonth ds
  164. End Sub
  165.  
  166. Sub btnMonth_Click (Index As Integer)
  167.     If Index = 0 Then
  168.         RetardMonth
  169.     Else
  170.         AdvanceMonth
  171.     End If
  172. End Sub
  173.  
  174. Sub btnYear_Click (Index As Integer)
  175.     If Index = 1 Then
  176.         AdvanceYear
  177.     Else
  178.         RetardYear
  179.     End If
  180. End Sub
  181.  
  182. Sub BuildCal ()
  183.     Dim i, l, t
  184.     ReDim DaysOfWeek(7) As String
  185.     Dim x1 As Integer
  186.     Dim x2 As Integer
  187.     Dim y1 As Integer
  188.     Dim y2 As Integer
  189.  
  190.     
  191.     DaysOfWeek(0) = "S"
  192.     DaysOfWeek(1) = "M"
  193.     DaysOfWeek(2) = "T"
  194.     DaysOfWeek(3) = "W"
  195.     DaysOfWeek(4) = "T"
  196.     DaysOfWeek(5) = "F"
  197.     DaysOfWeek(6) = "S"
  198.  
  199.     
  200.     
  201.     'Set control dimensions
  202.     h = Calendar.Height / 8
  203.     w = Calendar.Width / 7
  204.     
  205.     'Set headings
  206.     SetControl lblYear, h, 5 * w + 1, " ", &HC0C0C0
  207.     ControlText lblYear, True, &HC0, 2
  208.     lblYear.Move w, 0
  209.     
  210.     SetControl lblMonth, h, 5 * w + 1, " ", &HC0C0C0
  211.     ControlText lblMonth, True, &HC0, 2
  212.     lblMonth.Move w, h
  213.     
  214.    'set weekday heads
  215.    For i = 0 To 6
  216.     x1 = i * w + 10
  217.     y1 = 2 * h + 3
  218.     x2 = (i + 1) * w - 1
  219.     y2 = 3 * h - 1
  220.  
  221.     Calendar.CurrentX = x1 - 6 + (x2 - x1 - Picture1.TextWidth(DaysOfWeek(i))) / 2
  222.     Calendar.CurrentY = y1 + (y2 - y1 - Picture1.TextHeight(DaysOfWeek(i))) / 2
  223.     Calendar.Print DaysOfWeek(i)
  224.    Next i
  225.    
  226.    'set grdCal
  227.     Picture1.Move 0, 3 * h, 7 * w, 5 * h
  228.     Picture2.Visible = False
  229.    
  230.    'build cal grid
  231.     grid_build 7, 5
  232.     
  233.    
  234.    'Set buttons
  235.     btnYear(0).Move 0, 0, w, h
  236.     btnYear(0).Caption = "<"
  237.     Load btnYear(1)
  238.     btnYear(1).Visible = True
  239.     btnYear(1).Move 6 * w, 0
  240.     btnYear(1).Caption = ">"
  241.  
  242.     btnMonth(0).Move 0, h, w, h
  243.     btnMonth(0).Caption = "<"
  244.     Load btnMonth(1)
  245.     btnMonth(1).Visible = True
  246.     btnMonth(1).Move 6 * w, h
  247.     btnMonth(1).Caption = ">"
  248.  
  249. End Sub
  250.  
  251. Sub Command1_Click ()
  252.     Calendar.Visible = True
  253. End Sub
  254.  
  255. Sub ControlText (c As Control, wt, tcol, al)
  256.     c.FontBold = wt
  257.     c.ForeColor = tcol
  258.     c.Alignment = al
  259. End Sub
  260.  
  261. Function date_set (col As Integer, row As Integer) As Long
  262.     date_set = DateValue(lblMonth + " " + grid_text(row * 7 + col) + ", " + lblYear)
  263. End Function
  264.  
  265. Sub DayCalc (first, days)
  266.     Dim d, nday
  267.     Dim i As Integer
  268.     Dim c As Rect
  269.     Dim x1 As Integer
  270.     Dim x2 As Integer
  271.     Dim y1 As Integer
  272.     Dim y2 As Integer
  273.     Dim txtColor As Long
  274.     Dim col As Integer
  275.     Dim row As Integer
  276.  
  277.     For i = 0 To 33 + first
  278.        c = cell(i Mod 35)
  279.  
  280.        x1 = c.upper.x
  281.        y1 = c.upper.y
  282.        x2 = c.lower.x
  283.        y2 = c.lower.y
  284.        
  285.        'clear cell
  286.        Picture1.Line (x1 + 1, y1 + 1)-(x2 - 1, y2 - 1), Picture1.BackColor, BF
  287.         
  288.        d = i - first + 2
  289.        If d < 1 Or d > days Then
  290.           nday = " "
  291.        Else
  292.           nday = d
  293.        End If
  294.  
  295.        'display day number in cell
  296.         Picture1.CurrentX = x1 - 6 + (x2 - x1 - Picture1.TextWidth(nday)) / 2
  297.         Pictur